package socket

import (
	"card/app/framework/poker"
	"card/app/models"
	"github.com/gorilla/websocket"
	"sync"
	"time"
)

type LordPlayer struct {
	User *models.Member
	Conn *websocket.Conn
	sync.RWMutex
	Index         int
	IsReady       bool
	IsAuto        bool
	IsManager     bool
	MyCards       []poker.Poker
	callScoreChan chan int
	playCardsChan chan []int
	stopTimeChan  chan byte
	IsOnline      bool //是否在线，用于断线重连
	UpLineTime    time.Time
	OffLine       time.Time
	PokerRecorder []poker.Poker
}

func NewPlayer(user *models.Member, conn *websocket.Conn) *LordPlayer {
	player := &LordPlayer{
		User:          user,
		Conn:          conn,
		callScoreChan: make(chan int),
		playCardsChan: make(chan []int),
		stopTimeChan:  make(chan byte),
	}
	return player
}

func (p *LordPlayer) GetPlayerUser() *models.Member {
	return p.User
}

func (p *LordPlayer) PlayCardSuccess(cardIndexs []int) {

}

func (p *LordPlayer) PlayCardError(err string) {

}

func (p *LordPlayer) GetReadyStatus() bool {
	return p.IsReady
}

func (p *LordPlayer) GetAutoStatus() bool {
	return p.IsAuto
}

func (p *LordPlayer) GetIndex() int {
	return p.Index
}

func (p *LordPlayer) SetIndex(index int) {
	p.Lock()
	p.Index = index
	p.Unlock()
}
func (p *LordPlayer) SetPokerCards(cards poker.Poker) {

}

func (p *LordPlayer) StartCallScore() {

}
func (p *LordPlayer) GetPlayerCards(indexs []int) []poker.Poker {
	return nil
}

func (p *LordPlayer) StartPlay() {

}

func (p *LordPlayer) CallScore(score int) {
	p.stopTimeChan <- 1
	p.callScoreChan <- score
}

// 出牌
func (p *LordPlayer) PlayCards(cardIndexs []int) {
	p.RUnlock()
	p.stopTimeChan <- 1
	p.playCardsChan <- cardIndexs
}

// 按照桌号加入牌桌
func (p *LordPlayer) JoinGame(gameType int, gameId int) {

}

func (p *LordPlayer) LeaveGame() {

}

func (p *LordPlayer) IsOutOfCards() bool {
	return false
}

func (p *LordPlayer) SetManager() {
	p.IsManager = true
}

func (p *LordPlayer) SetReadyStatus() {
	p.IsReady = true
}
